﻿using System;
using Microsoft.Xna.Framework.Graphics;
using XnaGraphicsDeviceManager = Microsoft.Xna.Framework.GraphicsDeviceManager;

namespace WindowsGame.Manager
{
	/// <summary>
	/// GraphicsManager is responsible for managing all graphics properties.
	/// </summary>
	public interface IGraphicsManager
	{
		void Initialize(XnaGraphicsDeviceManager xnaGraphics);
		GraphicsDevice GraphicsDevice { get; }
		Single AspectRatio { get; }
		SpriteBatch SpriteBatch { get; }
	}

	public class GraphicsManager : IGraphicsManager
	{
		private XnaGraphicsDeviceManager graphics;

		// Initialize all graphics properties.
		public void Initialize(XnaGraphicsDeviceManager xnaGraphics)
		{
			if (null != graphics)
			{
				return;
			}

			graphics = xnaGraphics;
			graphics.PreferredBackBufferWidth = 800;
			graphics.PreferredBackBufferHeight = 480;
			graphics.IsFullScreen = false;
			graphics.ApplyChanges();

			GraphicsDevice = graphics.GraphicsDevice;
			SpriteBatch = new SpriteBatch(GraphicsDevice);
		}

		public GraphicsDevice GraphicsDevice { get; private set; }
		public Single AspectRatio { get { return GraphicsDevice.Viewport.AspectRatio; } }
		public SpriteBatch SpriteBatch { get; private set; }
	}
}